// Copyright (c) 2019 Presto Labs Pte. Ltd.
// Author: donggu

#include "coin2/base/window/time_window.h"

#include <gtest/gtest.h>

using coin2::base::window::TimeMovingWindow;

TEST(Base, TimeMovingWindow) {
  int64_t minute = 60 * 1'000'000'000ll;
  TimeMovingWindow w(5 * minute);  // n=0
  EXPECT_EQ(w.size(), 0);
  EXPECT_EQ(w.sum(), 0.0);
  // EXPECT_EQ(w.mean(), 0.0);

  w.Push(0, -9.0);  // n=1
  EXPECT_EQ(w.size(), 1);
  EXPECT_EQ(w.sum(), -9.0);
  EXPECT_EQ(w.mean(), -9.0);

  w.Push(3 * minute, 8.0);  // n=2
  EXPECT_EQ(w.size(), 2);
  EXPECT_EQ(w.sum(), -1.0);
  EXPECT_EQ(w.mean(), -0.5);

  w.Push(5 * minute - 1, 2.0);  // n=3
  EXPECT_EQ(w.size(), 3);
  EXPECT_EQ(w.sum(), 1.0);
  EXPECT_EQ(w.mean(), 1 / 3.);

  w.Push(5 * minute, -1.0);  // n=3
  EXPECT_EQ(w.size(), 3);
  EXPECT_EQ(w.sum(), 9.0);
  EXPECT_EQ(w.mean(), 3.0);

  w.Push(10 * minute, 1234.0);  // n=1
  EXPECT_EQ(w.size(), 1);
  EXPECT_EQ(w.sum(), 1234.0);
  EXPECT_EQ(w.mean(), 1234.0);
}

// TEST(Base, SecondOrderTimeWindow) {
// }
